`

You’ll learn about sending commands to the background in more

depth when we discuss job control in Chapter 2.

The && operator allows us to perform an AND operation between

two commands. In this case, the file test123 will be created only if

the first command was successful:

touch test && touch test123

The () operator allows us to group commands together so they

act a single unit when we need to redirect them together:

(ls; ps)

This is generally useful when you need to redirect results from

multiple commands to some stream, as shown in “Redirection

Operations” on page XX.

The ; operator allows us to run multiple commands irrespective

of their exit status:

ls; ps; whoami

As a result, each command is executed one after the other, as

soon as the previous one finishes.

The || operator allows us to chain commands together using an

OR operator:

lzl || echo "the lzl command failed"

In this example, the echo command will be executed only if the

first command fails.

Redirection Operators

The three standard streams we highlighted earlier can be

redirected from one program to another. Redirection is taking some

output from one command or script and using it as the input to

another. Table 1-6 describes the available redirection operators.

Table 1-6

Redirection Operators

Operator

Description

>

Redirects stdout to a file

>>

Redirects stdout to a file by appending it to the existing content

&> or >&

Redirects stdout and stderr to a file

&>>

Redirects stdout and stderr to a file by appending it to the existing content

<

Redirects input to a command

<<

Called a here document or heredoc, redirects multiple input lines to a com-

mand

Black Hat Bash (Early Access) © 2023 by Dolev Farhi and Nick Aleks